// pages/campDetails.js
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // tentTypeId：0,
    // 记录帐篷类型
    tentType: 0,
    tentTypePic: '',
    tentName: '',
    campId: 0,
    totalMoney: 0,
    peopleview: 'peopleview',
    people: 1,
    background: [],
    indicatorDots: false,
    vertical: false,
    autoplay: false,
    duration: 500,
    circular: false,
    swiperallcount: 3,
    swiperthennum: 1,
    camptitle: '-',
    province: '',
    city: '',
    address: '',
    campprice: '0',
    orderOrBusiness: 'order',

    height: 0,
    orderType: 0,  //点菜类型
    restaurant: false,  //餐厅点菜
    map_address: '',
    buycar_num: 0,
    block: false,  //选规格
    foodtype: 0,  //选规格种类
    bindId: 0,
    orderOrBusiness: 'order',
    //左侧菜单列表
    menu: [
      { id: 0, name: "帐篷" },
      { id: 1, name: "活动" },
      { id: 2, name: "早餐" }
    ],
    arrlist: [],
   // 时间选择的相关数据 
   multiArray: [['今天', '明天', '3-2'], [0, 1, 2, 3, 4, 5, 6], [0, 10, 20]],
   startDate: "点我选择入住时间",
   startTime: '',
   multiIndex: [0, 0, 0],
   currentHours: 0,
   currentMinute: 0,
   endDate: "点我选择离开时间",
   endTime: '',
   endmultiArray: [['今天', '明天', '3-2'], [0, 1, 2, 3, 4, 5, 6], [0, 10, 20]],
   endmultiIndex: [0, 0, 0],
   endcurrentHours: 0,
   endcurrentMinute: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const then = this
    wx.getSystemInfo({
      success: function (res) {
        then.setData({ 
          height: (res.windowHeight*.50)+'px'
        })
      }
    });
    var thatcampId = options.campId
    this.setData({
      campId: thatcampId
    })
    // 通过营地ID获取营地的详细信息
    this.getCampDetailed(options.campId)
    // 通过营地ID获取营地的帐篷类型信息
    this.getCampTentTyleList(options.campId)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 展示图片的滑动
  swiperchange: function (source) {
    this.setData({swiperthennum: source.detail.current + 1})
  },
  // 营地详情左侧列表点击
  // turnMenu: function(e) {
  //   var type = e.target.dataset.index;
  //   var datalist = this.data.arrAllList[type];
  //   this.setData({
  //     orderType: type,
  //     arrlist: datalist
  //   })
  // },
  // 商品的减少键
  reduce: function (e) {
    var i = e.currentTarget.dataset.id;
    var arr = this.data.arrlist;
    var buycar_num = this.data.buycar_num
    if (arr[i].num > 0) {  
      // 计算总商品价格
      // var Money = this.data.totalMoney
      // var price = Number(arr[i].price)
      // Money = 0
      arr[i].num = parseInt(arr[i].num) - 1;
      buycar_num = buycar_num - 1;
      // 重新计算商品价格
      this.setData({
        arrlist: arr,
        buycar_num: buycar_num,
        totalMoney: 0
      })
    }
  },
  // 商品的添加键
  add: function (e) {
    var that = this
    // 判断总数是否大于一
    if (this.data.buycar_num > 0) {
      wx.showToast({
        title: '只能选一种类型',
        icon: 'none',
        duration: 2000
      })
    } else {
      var i = e.currentTarget.dataset.id;
      console.log(i)
      console.log('tentid', e.currentTarget.dataset.tentid, e.currentTarget)
      var arr = this.data.arrlist;
      // var Money = this.data.totalMoney
      // var price = Number(arr[i].price)
      // Money = Money + price
      var buycar_num = this.data.buycar_num;
      arr[i].num = parseInt(arr[i].num) + 1;
      buycar_num = buycar_num + 1;
      this.setData({
        arrlist: arr,
        buycar_num: buycar_num,
        // totalMoney: Money,
        tentType: e.currentTarget.dataset.tentid,
        tentName: e.currentTarget.dataset.typename,
      })
      // 判断开始时间和结束时间有没有
      console.log(that.data.endTime, that.data.startTime)
      if (that.data.endTime != '' && that.data.startTime != '') {
          // 根据开始时间和结束时间计算价格
        this.getPrice(Math.ceil((new Date(that.data.endTime).getTime() - new Date(that.data.startTime).getTime())/3600000), that.data.tentType)
      }
    }
  },
  // 结算按钮点击事件
  choose: function (e) {
    var index = parseInt(e.currentTarget.dataset.id);
    var selected = this.data.arr[index].selected;
    var arr = this.data.arr;
    var totalMoney = this.data.totalMoney;
    var buycar_num = this.data.buycar_num;
    arr[index].selected = !selected;
    if (arr[index].selected) {
      totalMoney += Number(arr[index].price * arr[index].num);
      buycar_num += Number(arr[index].num);
    } else {
      totalMoney -= Number(arr[index].price * arr[index].num);
      buycar_num -= Number(arr[index].num);
    }
    totalMoney = Number(totalMoney).toFixed(2);
    this.setData({
      arr: arr,
      totalMoney: Number(totalMoney),
      buycar_num: buycar_num
    });
  },
  // 根据营地ID获取营地的详细信息
  getCampDetailed: function(id) {
    var that = this
    wx.showLoading({
      title: '营地信息获取中',
      mask: true
    })
    // 调用数据获取接口
    wx.request({
      url: `${app.globalData.testApiUrl}/api/wx/camp/detail`,
      data: {
        id: id
      },
      success: res => {
        // 处理返回的营地信息
        if (res.statusCode === 200) {
          console.log('营地详情', res)
          var imgArr = []
          imgArr.push(app.globalData.testApiUrl + res.data.campPic)
          //  处理返回的营地详情信息
          that.setData({
            camptitle: res.data.pathName,
            province: res.data.province,
            city: res.data.city,
            address: res.data.address,
            background: imgArr
          })
        }
      },
      fail: error => {
        wx.hideLoading()
      },
      complete: function (e) {
        app.errorDate.backData = e.data
        app.errorDate.statusCode = e.statusCode
        app.errorDate.route = 'campDetails'
        app.errorDate.interface = '/api/wx/camp/detail'
        app.setLogCloud()
        wx.hideLoading()
      }
    })
  },
  // 根据营地ID获取营地帐篷的类型
  getCampTentTyleList: function(id) {
    var that = this
    wx.showLoading({
      title: '帐篷信息获取中',
      mask: true
    })
    // 调用数据获取接口
    wx.request({
      url: `${app.globalData.testApiUrl}/api/wx/camp/listTenttype`,
      data: {
        id: id
      },
      success: res => {
        console.log('帐篷类型', res)
        // 处理返回的营地信息
        if (res.statusCode === 200) {
          var datalist = []
          for (var i in res.data) {
            datalist.push({
              id: res.data[i].id, 
              img: res.data[i].typePic ? app.globalData.testApiUrl + res.data[i].typePic : app.globalData.testApiUrl, 
              name: res.data[i].typeName, 
              num: 0, 
              price: res.data[i].price, 
              color: res.data[i].color, 
              allowPeople: res.data[i].allowPeople,
              message3: '',
              typeName: res.data[i].typeName,
            })
          }
          that.setData({
            arrlist: datalist
          })
          console.log('帐篷信息', res)
          //  处理返回的营地详情信息
        }
      },
      fail: error => {
        wx.hideLoading()
      },
      complete: function (e) {
        app.errorDate.backData = e.data
        app.errorDate.statusCode = e.statusCode
        app.errorDate.route = 'campDetails'
        app.errorDate.interface = '/api/wx/camp/listTenttype'
        app.setLogCloud()
        wx.hideLoading()
      }
    })
  },
  // 提交订单的结算按钮
  toSubmit: function() {
    var that = this
    // 判断是否有选中物品
    if (this.data.buycar_num < 1) {
       // 提示请输入时间
       wx.showToast({
        title: '您没有选择商品',
        icon: 'none',
        duration: 2000
      })
    } else {
      // 判断时间是否输入
      if (this.data.startTime && this.data.endTime) {
        // 计算入住时长
        var timelong = Number((new Date(that.data.endTime).getTime() - new Date(that.data.startTime).getTime())/3600000).toFixed(1)
        for (var i in this.data.arrlist) {
          console.log(this.data.arrlist[i])
          if (this.data.arrlist[i].id == this.data.tentType) {
            this.setData({
              tentTypePic: this.data.arrlist[i].img
            })
          }
        }
        console.log(that.data.tentTypePic)
        var data = {
          bookingHours: Number(timelong),
          campId: that.data.campId,
          personNo: that.data.people,
          price: that.data.totalMoney,
          tentTypePic: that.data.tentTypePic,
          tentTypeId: that.data.tentType,
          tentName: that.data.tentName,
          camptitle: that.data.camptitle,
          userId : app.globalData.userId,
        }
        data = JSON.stringify(data)
        // 这里判断一下登录状态
        if (!app.globalData.userInfo) {
          wx.showToast({
            title: '请登录用户！',
            icon: 'none',
            duration: 2000
          })
          return false
        } else {
          wx.navigateTo({
            url: `../submitOrder/submitOrder?tantdata=${data}`
          })
        }
      } else {
        // 提示请输入时间
        wx.showToast({
          title: '请输入入住和离开时间',
          icon: 'none',
          duration: 2000
        })
      }
    }
  },
  // 时间选择的相关函数
  pickerTap:function(el) {
    var date = new Date();
    var monthDay = ['今天','明天'];
    var hours = [];
    var minute = [];
    
    this.data.currentHours = date.getHours();
    this.data.currentMinute = date.getMinutes();
    // 月-日
    for (var i = 2; i <= 7; i++) {
      var date1 = new Date(date);
      date1.setDate(date.getDate() + i);
      var md = (date1.getMonth() + 1) + "-" + date1.getDate();
      monthDay.push(md);
    }
    var data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex
    };
    if(data.multiIndex[0] === 0) {
      if(data.multiIndex[1] === 0) {
        this.loadData(hours, minute);
      } else {
        this.loadMinute(hours, minute);
      }
    } else {
      this.loadHoursMinute(hours, minute);
    }

    data.multiArray[0] = monthDay;
    data.multiArray[1] = hours;
    data.multiArray[2] = minute;

    this.setData(data);
  },
  bindMultiPickerColumnChange: function(e) {
    var date = new Date();

    var that = this;

    var monthDay = ['今天', '明天'];
    var hours = [];
    var minute = [];

    this.data.currentHours = date.getHours();
    this.data.currentMinute = date.getMinutes();

    var data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex
    };
    // 把选择的对应值赋值给 multiIndex
    data.multiIndex[e.detail.column] = e.detail.value;

    // 然后再判断当前改变的是哪一列,如果是第1列改变
    if (e.detail.column === 0) {
      // 如果第一列滚动到第一行
      if (e.detail.value === 0) {

        that.loadData(hours, minute);
        
      } else {
        that.loadHoursMinute(hours, minute);
      }

      data.multiIndex[1] = 0;
      data.multiIndex[2] = 0;

      // 如果是第2列改变
    } else if (e.detail.column === 1) {

      // 如果第一列为今天
      if (data.multiIndex[0] === 0) {
        if (e.detail.value === 0) {
          that.loadData(hours, minute);
        } else {
          that.loadMinute(hours, minute);
        }
        // 第一列不为今天
      } else {
        that.loadHoursMinute(hours, minute);
      }
      data.multiIndex[2] = 0;

      // 如果是第3列改变
    } else {
      // 如果第一列为'今天'
      if (data.multiIndex[0] === 0) {

        // 如果第一列为 '今天'并且第二列为当前时间
        if(data.multiIndex[1] === 0) {
          that.loadData(hours, minute);
        } else {
          that.loadMinute(hours, minute);
        }
      } else {
        that.loadHoursMinute(hours, minute);
      }
    }
    data.multiArray[1] = hours;
    data.multiArray[2] = minute;
    this.setData(data);
  },

  loadData: function (hours, minute, data) {
    var minuteIndex = 0
    if (this.data.currentMinute > 0 && this.data.currentMinute <= 10) {
      minuteIndex = 10;
    } else if (this.data.currentMinute > 10 && this.data.currentMinute <= 20) {
      minuteIndex = 20;
    } else if (this.data.currentMinute > 20 && this.data.currentMinute <= 30) {
      minuteIndex = 30;
    } else if (this.data.currentMinute > 30 && this.data.currentMinute <= 40) {
      minuteIndex = 40;
    } else if (this.data.currentMinute > 40 && this.data.currentMinute <= 50) {
      minuteIndex = 50;
    } else {
      minuteIndex = 60;
    }

    if (minuteIndex == 60) {
      // 时
      for (var i = this.data.currentHours + 1; i < 24; i++) {
        hours.push(i);
      }
      // 分
      for (var i = 0; i < 60; i += 10) {
        minute.push(i);
      }
    } else {
      // 时
      for (var i = this.data.currentHours; i < 24; i++) {
        hours.push(i);
      }
      // 分
      for (var i = minuteIndex; i < 60; i += 10) {
        minute.push(i);
      }
    }
  },

  loadHoursMinute: function (hours, minute){
    // 时
    for (var i = 0; i < 24; i++) {
      hours.push(i);
    }
    // 分
    for (var i = 0; i < 60; i += 10) {
      minute.push(i);
    }
  },

  loadMinute: function (hours, minute) {
    var minuteIndex;
    if (this.data.currentMinute > 0 && this.data.currentMinute <= 10) {
      minuteIndex = 10;
    } else if (this.data.currentMinute > 10 && this.data.currentMinute <= 20) {
      minuteIndex = 20;
    } else if (this.data.currentMinute > 20 && this.data.currentMinute <= 30) {
      minuteIndex = 30;
    } else if (this.data.currentMinute > 30 && this.data.currentMinute <= 40) {
      minuteIndex = 40;
    } else if (this.data.currentMinute > 40 && this.data.currentMinute <= 50) {
      minuteIndex = 50;
    } else {
      minuteIndex = 60;
    }

    if (minuteIndex == 60) {
      // 时
      for (var i = this.data.currentHours + 1; i < 24; i++) {
        hours.push(i);
      }
    } else {
      // 时
      for (var i = this.data.currentHours; i < 24; i++) {
        hours.push(i);
      }
    }
    // 分
    for (var i = 0; i < 60; i += 10) {
      minute.push(i);
    }
  },

  // 时间选择控件的确定按钮
  bindStartMultiPickerChange: function (e) {
    var that = this;
    var monthDay = that.data.multiArray[0][e.detail.value[0]];
    var hours = that.data.multiArray[1][e.detail.value[1]];
    var minute = that.data.multiArray[2][e.detail.value[2]];
    var date = new Date()
    if (monthDay === "今天") {
      var month = date.getMonth()+1;
      var day = date.getDate();
      monthDay = month + "月" + day + "日";
    } else if (monthDay === "明天") {
      var date1 = new Date();
      date1.setDate(date.getDate() + 1);
      var month = date1.getMonth() + 1;
      var day = date1.getDate();
      monthDay = (date1.getMonth() + 1) + "月" + date1.getDate() + "日";
    } else {
      var month = monthDay.split("-")[0]; // 返回月
      var day = monthDay.split("-")[1]; // 返回日
      monthDay = month + "月" + day + "日";
    }
    var startDate = monthDay + " " + (hours<10? '0'+hours : hours) + ":" + (minute<10 ? '0'+minute : minute);
    var startTime = date.getFullYear() +"-"+ month +"-"+ day + " "+ hours + ":" + minute;
    // 判断一下选择时长是否长于8小时
    if (this.data.endTime) {
      var endTimeNum = new Date(this.data.endTime)
      var startTimeNum = new Date(startTime)
      if (endTimeNum.getTime() - startTimeNum.getTime() < 28800000) {
        startTimeNum = new Date(startTimeNum.getTime() + 28800000)
        var yearstr = startTimeNum.getFullYear()
        var monthstr = startTimeNum.getMonth() + 1
        var daystr = startTimeNum.getDate()
        var hoursstr = startTimeNum.getHours()
        var minstr = startTimeNum.getMinutes()
        // 设置结束时间为开始时间的8小时后
        var endTime = yearstr +"-"+ monthstr +"-"+ daystr + " "+ hoursstr + ":" + minstr;
        var endDate = monthstr + "月" + daystr + "日 " + (hoursstr<10? '0'+hoursstr : hoursstr) + ":" + (minstr<10 ? '0'+minstr : minstr)
        that.setData({
          endDate: endDate,
          endTime: endTime
        })
      }
    }
    that.setData({
      startDate: startDate,
      startTime: startTime,
    })
      // 判断是否拥有帐篷类型
      if (that.data.tentType) {
        // 根据开始时间和结束时间计算价格
       this.getPrice(Math.ceil((new Date(that.data.endTime).getTime() - new Date(that.data.startTime).getTime())/3600000), that.data.tentType)
     }
  },

  // 计算价格函数
  getPrice:function(Time, tentType) {
    console.log(Time)
    var that = this
    if (Time && tentType) {
      wx.request({
        url: `${app.globalData.testApiUrl}/api/wx/order/getPrice`,
        data: {
          bookingHours: Time,
          tentTypeId: tentType
        },
        success: (res) => {
          console.log('请求成功', res)
          // 更新页面价格
          that.setData({
            totalMoney: Number(res.data.price).toFixed(2),
          })
        },
        fail: (err)=> {

        },
        complete: function(e){
          app.errorDate.backData = e.data
          app.errorDate.statusCode = e.statusCode
          app.errorDate.route = 'campDetails'
          app.errorDate.interface = '/api/wx/order/getPrice'
          app.setLogCloud()
        }
      })
    }
  },
// 结束时间picker的bindcolumnchange事件
  bindMultiPickerColumnChangeEnd:function(e) {
    var date = new Date();

    var that = this;

    var monthDay = ['今天', '明天'];
    var hours = [];
    var minute = [];

    this.data.endcurrentHours = date.getHours();
    this.data.endcurrentMinute = date.getMinutes();

    var data = {
      endmultiArray: this.data.endmultiArray,
      endmultiIndex: this.data.endmultiIndex
    };
    // 把选择的对应值赋值给 multiIndex
    data.endmultiIndex[e.detail.column] = e.detail.value;

    // 然后再判断当前改变的是哪一列,如果是第1列改变
    if (e.detail.column === 0) {
      // 如果第一列滚动到第一行
      if (e.detail.value === 0) {

        that.loadDataEnd(hours, minute);
        
      } else {
        that.loadHoursMinuteEnd(hours, minute);
      }

      data.endmultiIndex[1] = 0;
      data.endmultiIndex[2] = 0;

      // 如果是第2列改变
    } else if (e.detail.column === 1) {

      // 如果第一列为今天
      if (data.endmultiIndex[0] === 0) {
        if (e.detail.value === 0) {
          that.loadDataEnd(hours, minute);
        } else {
          that.loadMinuteEnd(hours, minute);
        }
        // 第一列不为今天
      } else {
        that.loadHoursMinuteEnd(hours, minute);
      }
      data.endmultiIndex[2] = 0;

      // 如果是第3列改变
    } else {
      // 如果第一列为'今天'
      if (data.endmultiIndex[0] === 0) {

        // 如果第一列为 '今天'并且第二列为当前时间
        if(data.endmultiIndex[1] === 0) {
          that.loadDataEnd(hours, minute);
        } else {
          that.loadMinuteEnd(hours, minute);
        }
      } else {
        that.loadHoursMinuteEnd(hours, minute);
      }
    }
    data.endmultiArray[1] = hours;
    data.endmultiArray[2] = minute;
    this.setData(data);
  },

  loadDataEnd: function (hours, minute) {
    var minuteIndex = 0
    if (this.data.endcurrentMinute > 0 && this.data.endcurrentMinute <= 10) {
      minuteIndex = 10;
    } else if (this.data.endcurrentMinute > 10 && this.data.endcurrentMinute <= 20) {
      minuteIndex = 20;
    } else if (this.data.endcurrentMinute > 20 && this.data.endcurrentMinute <= 30) {
      minuteIndex = 30;
    } else if (this.data.endcurrentMinute > 30 && this.data.endcurrentMinute <= 40) {
      minuteIndex = 40;
    } else if (this.data.endcurrentMinute > 40 && this.data.endcurrentMinute <= 50) {
      minuteIndex = 50;
    } else {
      minuteIndex = 60;
    }

    if (minuteIndex == 60) {
      // 时
      for (var i = this.data.endcurrentHours + 1; i < 24; i++) {
        hours.push(i);
      }
      // 分
      for (var i = 0; i < 60; i += 10) {
        minute.push(i);
      }
    } else {
      // 时
      for (var i = this.data.endcurrentHours; i < 24; i++) {
        hours.push(i);
      }
      // 分
      for (var i = minuteIndex; i < 60; i += 10) {
        minute.push(i);
      }
    }
  },

  loadHoursMinuteEnd: function (hours, minute){
    // 时
    for (var i = 0; i < 24; i++) {
      hours.push(i);
    }
    // 分
    for (var i = 0; i < 60; i += 10) {
      minute.push(i);
    }
  },

  loadMinuteEnd: function (hours, minute) {
    var minuteIndex;
    if (this.data.endcurrentMinute > 0 && this.data.endcurrentMinute <= 10) {
      minuteIndex = 10;
    } else if (this.data.endcurrentMinute > 10 && this.data.endcurrentMinute <= 20) {
      minuteIndex = 20;
    } else if (this.data.endcurrentMinute > 20 && this.data.endcurrentMinute <= 30) {
      minuteIndex = 30;
    } else if (this.data.endcurrentMinute > 30 && this.data.endcurrentMinute <= 40) {
      minuteIndex = 40;
    } else if (this.data.endcurrentMinute > 40 && this.data.endcurrentMinute <= 50) {
      minuteIndex = 50;
    } else {
      minuteIndex = 60;
    }

    if (minuteIndex == 60) {
      // 时
      for (var i = this.data.endcurrentHours + 1; i < 24; i++) {
        hours.push(i);
      }
    } else {
      // 时
      for (var i = this.data.endcurrentHours; i < 24; i++) {
        hours.push(i);
      }
    }
    // 分
    for (var i = 0; i < 60; i += 10) {
      minute.push(i);
    }
  },

  bindStartMultiPickerChangeEnd: function (e) {
    var that = this;
    var monthDay = that.data.endmultiArray[0][e.detail.value[0]];
    var hours = that.data.endmultiArray[1][e.detail.value[1]];
    var minute = that.data.endmultiArray[2][e.detail.value[2]];
    var date = new Date()
    if (monthDay === "今天") {
      var month = date.getMonth()+1;
      var day = date.getDate();
      monthDay = month + "月" + day + "日";
    } else if (monthDay === "明天") {
      var date1 = new Date();
      date1.setDate(date.getDate() + 1);
      var month = date1.getMonth() + 1;
      var day = date1.getDate();
      monthDay = (date1.getMonth() + 1) + "月" + date1.getDate() + "日";
    } else {
      var month = monthDay.split("-")[0]; // 返回月
      var day = monthDay.split("-")[1]; // 返回日
      monthDay = month + "月" + day + "日";
    }
    var endDate = monthDay + " " + (hours<10? '0'+hours : hours) + ":" + (minute<10 ? '0'+minute : minute);
    var endTime = date.getFullYear() +"-"+ month +"-"+ day + " "+ hours + ":" + minute;
    // 判断一下选择时长是否长于8小时
    if (this.data.startTime) {
      var endTimeNum = new Date(endTime)
      var startTimeNum = new Date(this.data.startTime)
      if (endTimeNum.getTime() - startTimeNum.getTime() < 28800000) {
        startTimeNum = new Date(startTimeNum.getTime() + 28800000)
        var yearstr = startTimeNum.getFullYear()
        var monthstr = startTimeNum.getMonth() + 1
        var daystr = startTimeNum.getDate()
        var hoursstr = startTimeNum.getHours()
        var minstr = startTimeNum.getMinutes()
        // 设置结束时间为开始时间的8小时后
        endTime = yearstr +"-"+ monthstr +"-"+ daystr + " "+ hoursstr + ":" + minstr;
        endDate = monthstr + "月" + daystr + "日 " + (hoursstr<10? '0'+hoursstr : hoursstr) + ":" + (minstr<10 ? '0'+minstr : minstr)
      }
    }
    that.setData({
      endDate: endDate,
      endTime: endTime
    })
    // 判断是否拥有帐篷类型
    if (that.data.tentType) {
      // 根据开始时间和结束时间计算价格
      this.getPrice(Math.ceil((new Date(that.data.endTime).getTime() - new Date(that.data.startTime).getTime())/3600000), that.data.tentType)
   }
  },
  // 时间选择的相关函数
  pickerTapEnd:function(el) {
    var date = new Date();
    var monthDay = ['今天','明天'];
    var hours = [];
    var minute = [];
    
    this.data.endcurrentHours = date.getHours();
    this.data.endcurrentMinute = date.getMinutes();
    // 月-日
    for (var i = 2; i <= 7; i++) {
      var date1 = new Date(date);
      date1.setDate(date.getDate() + i);
      var md = (date1.getMonth() + 1) + "-" + date1.getDate();
      monthDay.push(md);
    }
    var data = {
      endmultiArray: this.data.endmultiArray,
      endmultiIndex: this.data.endmultiIndex
    };
    if(data.endmultiIndex[0] === 0) {
      if(data.endmultiIndex[1] === 0) {
        this.loadDataEnd(hours, minute);
      } else {
        this.loadMinuteEnd(hours, minute);
      }
    } else {
      this.loadHoursMinuteEnd(hours, minute);
    }

    data.endmultiArray[0] = monthDay;
    data.endmultiArray[1] = hours;
    data.endmultiArray[2] = minute;

    this.setData(data);
  },

  peoplereduce: function () {
    // 判断人数是否为0
    if (this.data.people > 0) {
      var peoplenum = this.data.people
      peoplenum = peoplenum - 1
      this.setData({
        people: peoplenum
      })
    } 
  },

  peopleadd: function () {
    var peoplenum = this.data.people
    peoplenum = peoplenum + 1
    this.setData({
      people: peoplenum
    })
  }
})

